package com.situ.edu.controller;

import com.situ.edu.pojo.entity.User;
import com.situ.edu.pojo.query.CourseQuery;
import com.situ.edu.service.IStudentHisService;
import com.situ.edu.service.impl.StudentHisServiceImpl;
import com.situ.edu.util.MyBeanUtils;
import com.situ.edu.util.PageInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/studentHis")
public class StudentHisContorller extends BaseController {
    private IStudentHisService studentHisService = new StudentHisServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        switch (method){
            case "selectByPage"://观看所有的选课记录
                selectByPage(req,resp);
                break;
        }
    }

    private void selectByPage(HttpServletRequest req, HttpServletResponse resp) {
        System.out.println("StudentHisContorller.selectByPage");

        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");
        String name = user.getName();
        String password = user.getPassword();

        CourseQuery courseQuery = MyBeanUtils.copyToBean(req,CourseQuery.class);


        //PageInfo pageInfo = studentHisService.selectByPage(courseQuery);
        PageInfo pageInfo = studentHisService.selectByPage(courseQuery,name,Integer.parseInt(password));

        toJSON(resp,pageInfo);
    }
}
